/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class ArrayBankQueue <E> extends AbstractQueue{

    public Object[] elements;
    public int start, end;

    public ArrayBankQueue(int s){
        this.size = s;
        elements = new Object[this.size];
        start = 0;
        end = 0;
    }

    public void queue(Object o) throws QueueOverflow{
        QueueOverflow error = new QueueOverflow("Queue Overflow");

        if((end >= start) && !(this.getFull())){
            elements[end] = o;
            end++;
            end = end % this.size;
            this.count++;
        }
        else
            throw error;
    }

    public E dequeue() throws QueueUnderflow{
        QueueUnderflow error = new QueueUnderflow("Queue Underflow");

        if(!this.getEmpty()){
            Object temp = elements[start];
            start++;
            start = start % this.size;
            this.count--;
            return((E)temp);
        }
        else
            throw error;
    }

    public E peek() throws QueueUnderflow{
        QueueUnderflow error = new QueueUnderflow("Queue Underflow");

        if (!this.getEmpty())
            return((E)elements[start]);
        else
            throw error;
    }
}
